****************************************************************************************
*** Replication Code                                                                 ***
*** Title: Overestimation of the Level of Democracy among Citizens in Nondemocracies ***
*** Author: Eddy S. F. Yeung                                                         ***
*** Version: March 5, 2022                                                           ***
****************************************************************************************

*** Set-up ***
// Clean the Stata environment and set the working directory
// Stata version BE 17.0 for Mac (Intel 64-bit)
clear all
cd "~/Desktop/CPS_replication"
use "dataset_cleaned.dta"

// Categorize each country as a nondemocracy or democracy
gen nondemocracy = 1
replace nondemocracy = 0 if v2x_regime == 2 | v2x_regime == 3
label define Nondemocracy 0 "Democracy" 1 "Nondemocracy"
label values nondemocracy Nondemocracy

// Categorize each individual as a highly educated citizen or not
gen university = .
replace university = 1 if V248 == 9
replace university = 0 if V248 > 0 & V248 < 9
label define University 0 "Less Educated Citizen" 1 "Highly Educated Citizen"
label values university University

// Define all nonresponses as NA
replace V131 = . if V131 < 0
replace V132 = . if V132 < 0
replace V133 = . if V133 < 0
replace V134 = . if V134 < 0
replace V135 = . if V135 < 0
replace V136 = . if V136 < 0
replace V137 = . if V137 < 0
replace V138 = . if V138 < 0
replace V139 = . if V139 < 0

*** Figure S1 ***
// Set the plot scheme (run the two following lines to replicate the asethetics of the graphs)
* net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
* set scheme cleanplots

// V133: people choose their leaders in free elections
twoway histogram V133, discrete by(nondemocracy, note("")) ///
	xtitle("People Choose Their Leaders in Free Elections" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S1a.pdf", replace

// V136: civil rights protect people's liberty from state oppression
twoway histogram V136, discrete by(nondemocracy, note("")) ///
	xtitle("Civil Rights Protect People's Liberty from State Oppression" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S1b.pdf", replace

// V139: women have the same rights as men
twoway histogram V139, discrete by(nondemocracy, note("")) ///
	xtitle("Women Have the Same Rights as Men" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S1c.pdf", replace

*** Figure S2 ***
// V131: governments tax the rich and subsidize the poor
twoway histogram V131, discrete by(nondemocracy, note("")) ///
	xtitle("Governments Tax the Rich and Subsidize the Poor" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S2a.pdf", replace

// V134: people receive state aid for unemployment
twoway histogram V134, discrete by(nondemocracy, note("")) ///
	xtitle("People Receive State Aid for Unemployment" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S2b.pdf", replace

// V137: the state makes people's incomes equal
twoway histogram V137, discrete by(nondemocracy, note("")) ///
	xtitle("The State Makes People's Incomes Equal" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S2c.pdf", replace

*** Figure S3 ***
// V132: religious authorities interpret the laws
twoway histogram V132, discrete by(nondemocracy, note("")) ///
	xtitle("Religious Authorities Interpret the Laws" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S3a.pdf", replace

// V135: the army takes over when government is incompetent
twoway histogram V135, discrete by(nondemocracy, note("")) ///
	xtitle("The Army Takes Over When Government Is Incompetent" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S3b.pdf", replace

// V138: people obey their rulers
twoway histogram V138, discrete by(nondemocracy, note("")) ///
	xtitle("People Obey Their Rulers" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S3c.pdf", replace

*** Figure S4 ***
// V133: people choose their leaders in free elections
twoway histogram V133 if nondemocracy == 1, discrete by(university, note("")) ///
	xtitle("People Choose Their Leaders in Free Elections" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S4a.pdf", replace

// V136: civil rights protect people's liberty from state oppression
twoway histogram V136 if nondemocracy == 1, discrete by(university, note("")) ///
	xtitle("Civil Rights Protect People's Liberty from State Oppression" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S4b.pdf", replace

// V139: women have the same rights as men
twoway histogram V139 if nondemocracy == 1, discrete by(university, note("")) ///
	xtitle("Women Have the Same Rights as Men" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S4c.pdf", replace

*** Figure S5 ***
// V131: governments tax the rich and subsidize the poor
twoway histogram V131 if nondemocracy == 1, discrete by(university, note("")) ///
	xtitle("Governments Tax the Rich and Subsidize the Poor" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S5a.pdf", replace

// V134: people receive state aid for unemployment
twoway histogram V134 if nondemocracy == 1, discrete by(university, note("")) ///
	xtitle("People Receive State Aid for Unemployment" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S5b.pdf", replace

// V137: the state makes people's incomes equal
twoway histogram V137 if nondemocracy == 1, discrete by(university, note("")) ///
	xtitle("The State Makes People's Incomes Equal" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S5c.pdf", replace

*** Figure S6 ***
// V132: religious authorities interpret the laws
twoway histogram V132 if nondemocracy == 1, discrete by(university, note("")) ///
	xtitle("Religious Authorities Interpret the Laws" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S6a.pdf", replace

// V135: the army takes over when government is incompetent
twoway histogram V135 if nondemocracy == 1, discrete by(university, note("")) ///
	xtitle("The Army Takes Over When Government Is Incompetent" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S6b.pdf", replace

// V138: people obey their rulers
twoway histogram V138 if nondemocracy == 1, discrete by(university, note("")) ///
	xtitle("People Obey Their Rulers" "(1 = Not Essential; 10 = Essential Characteristic of Democracy)") ///
	xscale(range(1 10)) ysize(1.7) xsize(3)
graph export "~/Desktop/CPS_replication/figures/Figure S6c.pdf", replace

*** Figure S7 ***
// Generate Figure S7 to show to what extent citizens in nondemocracies value democracy
histogram V140 if nondemocracy == 1 & V140 > 0, discrete ///
	xtitle("Importance of Democracy" "(1 = Not at All Important; 10 = Absolutely Important)") ///
	xscale(range(1 10)) ysize(3) xsize(4)
graph export "~/Desktop/CPS_replication/figures/Figure S7.pdf", replace

*** Table S7 ***
// Drop nonrespondents of V141 (perceived level of democracy)
drop if V141 == -1 | V141 == -2 | V141 == -3 | V141 == -4 | V141 == -5

// Marital status (V57)
gen married = .
replace married = 1 if V57 == 1
replace married = 0 if V57 > 1 & V57 < 7

// Employment status (V229)
gen unemployed = .
replace unemployed = 1 if V229 == 7
replace unemployed = 0 if (V229 > 0 & V229 < 7) | V229 == 8

// Income (V239)
gen income = .
replace income = 0 if V239 == 1
replace income = 1 if V239 == 2
replace income = 2 if V239 == 3
replace income = 3 if V239 == 4
replace income = 4 if V239 == 5
replace income = 5 if V239 == 6
replace income = 6 if V239 == 7
replace income = 7 if V239 == 8
replace income = 8 if V239 == 9
replace income = 9 if V239 == 10

// Subjective social class (V238)
gen social_class = .
replace social_class = 0 if V238 == 5
replace social_class = 1 if V238 == 4
replace social_class = 2 if V238 == 3
replace social_class = 3 if V238 == 2
replace social_class = 4 if V238 == 1

// Sex (V240)
gen female = .
replace female = 1 if V240 == 2
replace female = 0 if V240 == 1

// Age (V242)
gen age = V242
replace age = . if V242 == -1 | V242 == -2 | V242 == -3 | V242 == -4 | V242 == -5

// Generate age squared variable
gen age_sq = age ^ 2 / 100

** Generate Table S7 to show whether highly educated citizens in democracies are
** more critical of the regime democraticness in their country compared to their
** less educated peers
// Model 1
eststo EDU1: reg V141 university i.code ///
	if nondemocracy == 0, robust

// Model 2
eststo EDU2: reg V141 university i.code ///
	female age age_sq ///
	if nondemocracy == 0, robust

// Model 3
eststo EDU3: reg V141 university i.code ///
	female age age_sq ///
	married unemployed income social_class ///
	if nondemocracy == 0, robust

// Export table (Table S7 is modified from this exported table)
esttab EDU* using "~/Desktop/CPS_replication/tables/Table S7.tex", ///
	replace se b(4) star(* 0.10 ** 0.05 *** 0.01)
eststo clear
